package com.uyayo.framework.common.util.thread;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool  implements Pool{
	
  private ExecutorService pool;
  private static ThreadPool instance;

  public static ThreadPool getInstance(){
	  if(instance==null){ //判断是否已经有对象，有就不用等待了
		  synchronized (ThreadPool.class) {
		    if (instance == null) {
		      instance = new ThreadPool();
		    }
		  }
	  }
    return instance;
  }

  public ThreadPool() {
    this.pool = Executors.newCachedThreadPool();
  }

  public void destroy(){
    if (this.pool != null)
      this.pool.shutdown();
  }

  public void execute(Task task){
    this.pool.execute(task);
  }
}